package cn.classTest.mall.service.impl;

import cn.classTest.mall.domain.Mall;
import cn.classTest.mall.mapper.MallMapper;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.MallService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallServiceImpl implements MallService {
    @Autowired
    private MallMapper mallMapper;

    @Override
    public void saveOrUpdate(Mall mall) {
        if (mall.getId() == null) {
            mallMapper.save(mall);
        } else {
            mallMapper.update(mall);
        }

    }

    @Override
    public void delete(Long id) {
        mallMapper.delete(id);
    }

    @Override
    public Mall selectOne(Long id) {
        return mallMapper.selectOne(id);
    }

    @Override
    public List<Mall> selectAll() {
        return mallMapper.selectAll();
    }

    @Override
    public PageInfo<Mall> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Mall> malls = mallMapper.selectAll();
        System.out.println(malls);
        PageInfo<Mall> pageInfo = new PageInfo<>(malls);

        return pageInfo;
    }
}
